package com.hxht.cmp.controller;

import com.hxht.cmp.common.enums.ResultCode;
import com.hxht.cmp.common.result.ResultResponse;
import com.hxht.cmp.pojo.SearchCriteria;
import com.hxht.cmp.service.JudgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/judge")
public class JudgeInformationController {
    @Autowired
    private JudgeService judgeService;

    /**
     *根据多个法官Id查询案件排期或回顾
     *
     * @param searchCriteria
     * @return
     */
    @RequestMapping("/selectJudgeCasePlanOrReview")
    @ResponseBody
    public ResultResponse selectJudgeCasePlanOrReview(SearchCriteria searchCriteria) {
        if (ObjectUtils.isEmpty(searchCriteria)) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        if (ObjectUtils.isEmpty(searchCriteria.getReview()) || ObjectUtils.isEmpty(searchCriteria.getJudgeList()) || ObjectUtils.isEmpty(searchCriteria.getStartDate())) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        List<Map<String, Object>> mapList = judgeService.selectJudgeCasePlanOrReview(searchCriteria);
        return ResultResponse.success(mapList);
    }

    /**
     * 多法官的更多开庭和更多回顾
     * @param searchCriteria
     * @return
     */
    @RequestMapping("/selectMoreCasePlanOrReview")
    public ResultResponse selectMoreCasePlanOrReview(SearchCriteria searchCriteria) {
        if (ObjectUtils.isEmpty(searchCriteria)) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        if (ObjectUtils.isEmpty(searchCriteria.getReview()) || ObjectUtils.isEmpty(searchCriteria.getJudgeList())) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        if (searchCriteria.getPage() < 1 || searchCriteria.getPageSize() < 1) {
            return ResultResponse.failed(ResultCode.PARAMETER_NULL);
        }
        Map<String, Object> map = judgeService.selectMoreCasePlanOrReview(searchCriteria);
        return ResultResponse.success(map);
    }

}
